/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author robert
 */
public class GeneralLengthValidator implements Validator{

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        String strVal = (String)value;
        if (strVal.length() < 2 || strVal.length()>45)
        {
            FacesMessage msg = new FacesMessage();
            msg.setDetail("Value must be between 2 and 45 characters!");
            msg.setSummary("Value must be between 2 and 45 characters!");
            msg.setSeverity(FacesMessage.SEVERITY_ERROR);
            throw new ValidatorException(msg);
        }
    }
    
}
